package com.lincoln.cloud.serverclient.interfaces;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 心跳处理线程
 *
 * @author lincoln
 */
public class HeartBeatThread extends Thread {
    private static final Logger logger = LoggerFactory.getLogger(HeartBeatThread.class);

    @Override
    public void run() {
        while (true) {
            try {
                boolean res = ServerClientContext.communicationProtocol().checkHeart();
                if (res == true) {
                    logger.info("发送心跳");
                    try {
                        sleep(Integer.parseInt(ServerClientContext.loadProperties().getProperty("timeout")) * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    logger.error("发送心跳失败");
                    continue;
                }
            } catch (Exception e) {
                logger.error("发送心跳出现异常{}", e);
            }
        }
    }
}
